// function createArray(value: any, length: number): any[] {
//   const arr: any[] = [];
//   for (let i = 0; i < length; i++) {
//     arr.push(value);
//   }
//   return arr;
// }
// const arr1 = createArray(1, 10);
// const arr2 = createArray({}, 10);
// const arr3 = createArray("hello", 10);
// arr3[0].filter(() => {})

// 泛型：在定义函数、接口或类的时候，不预先指定具体的类型，而在使用的时候再指定具体类型
// 定义泛型参数：函数名称<泛型参数>
function createArray<T>(value: T, length: number): T[] {
  const arr: T[] = [];
  for (let i = 0; i < length; i++) {
    arr.push(value);
  }
  return arr;
}
// const arr1 = createArray<number>(1, 10);
const arr1 = createArray(1, 10);
const arr2 = createArray<{}>({}, 10);
// const arr3 = createArray<string>("hello", 10);
const arr3 = createArray("hello", 10);

interface IResponse<T> {
  code: number;
  message: string;
  data: T;
  ok: boolean;
}

// 泛型参数可以有n个
class Person<T, K, U, I> {}

new Person<string, number, boolean, number>();

// 泛型参数默认类型
class Person1<T, K, U, I = string> {}

new Person1<string, number, boolean>();

// 泛型参数有约束条件
interface IPerson {
  name: string;
}
class Person2<T extends IPerson> {}
new Person2<{ name: string; age: number }>();

interface IData {
  name: string;
  age: number;
  sex: number;
  address?: string;
  phone: number;
  password: string;
}

// const data1: IData = {
//   name: "",
//   age: 0,
//   sex: 0,
//   address: "",
//   phone: 0,
//   password: "",
// };

// 泛型工具类型
// Pick 从类型中挑选一部分属性组成一个新类型
const data2: Pick<IData, "phone" | "password"> = {
  phone: 0,
  password: "",
};

// Omit 从类型中排除一部分属性，剩下属性组成一个新类型
const data3: Omit<IData, "name" | "age" | "sex" | "address"> = {
  phone: 0,
  password: "",
};

// Required 将类型中所有属性变成必选属性
const data4: Required<IData> = {
  name: "",
  age: 0,
  sex: 0,
  address: "",
  phone: 0,
  password: "",
};

// Partial 将类型中所有属性变成可选属性
const data5: Partial<IData> = {};
